import axios from "axios";
import { defineStore } from "pinia";
import router from "@/router";
const userCount = defineStore("userCount", {
  state() {
    return {
      userid: 0,
      contentid: 0,
      todolist: [] /* 全部待办 */,
      userInfo: [] /* 用户信息 */,
      todaylist: [] /* 当天待办 */,
      weeklist: [] /* 按周查询 */,
      updatelist: [] /* 修改数据回显 */,
      day: "" /* 哪天 */,
      searchlist: [] /* 搜索出来的数据 */,
      todoid: 0 /* 待办编号 */,
      /* show: false, */
      dataInfo: {
        countDay: Number,
        countMonth: Number,
        countWeek: Number,
        doneDay: Number,
        doneMonth: Number,
        doneWeek: Number,
        percentDay: Number,
        percentMonth: Number,
        percentWeek: Number,
        countStudy: Number,
        countWork: Number,
        countLife: Number,
        countEnter: Number,
      },
    };
  },
  actions: {
    getAll() {
      axios
        .post(`http://8.130.43.203:8080/content/todo/${this.userid}`)
        .then((res) => {
          console.log(res.data);
          this.todolist = res.data;
          console.log(this.todolist);
          // router.push('/add')
        });
    },

    getCount() {
      axios
        .post(`http://8.130.43.203:8080/content/donePercent/${this.userid}`)
        .then((res) => {
          /* console.log(res.data) */
          this.dataInfo = res.data;
          console.log(this.dataInfo);
          router.push("/add");
        });
    },
  },
  persist: {
    enabled: true, // 这个配置代表存储生效，而且是整个store都存储
  },
});
export default userCount;
